package nz.ac.massey.cs.presentaion;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SpringLayout.Constraints;

import nz.ac.massey.cs.domain.IConstraint;
import nz.ac.massey.cs.domain.ISudoku;

public class jigsawDrawer {

	/*
	 * takes a sudoku board customises it to the specifications required for this sudoku
	 */
	public JPanel buildSudokuBoard(ISudoku sudoku,JPanel sudokuBoard,JButton[][] buttons)
	{
		sudokuBoard.removeAll();
		sudokuBoard.setLayout(new GridLayout(sudoku.getColSize()+1,sudoku.getRowSize()+1,1,1));
		sudokuBoard.setBackground(Color.cyan);
		
		for(int y = 0; y < sudoku.getColSize(); y++)
		{
			for(int x = 0; x < sudoku.getRowSize();x++)
			{
				JButton button = new JButton(sudoku.getCellByIndex(y, x).getValue());
				sudokuBoard.add(button);
				buttons[y][x] = button;
				
				for(IConstraint con:sudoku.getCellByIndex(y, x).getConstraints())
				{
					String colour = con.getDrawingInfo().get("Border-Colour");
					if(colour != null)
					{
						button.setBackground(new Color(Integer.parseInt(colour)));
//						sudokuBoard.getComponentAt(i, k).setContentAreaFilled(false);
//						sudokuBoard.getComponentAt(i, k).setOpaque(true); 
					}
				}
			}
		}
		return sudokuBoard;
	}
}
